<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function lengthOfString(s){
            let map = new Map()
            let i=-1
            let res = 0;
            let n = s.length
            for(let j=0;j<n;j++){
                if(map.has(s[j])){
                    i = Math.max(i,map.has(s[j]))
                }
                res = Math.max(res,j-i)
                map.set(s[j],j)//j为s[j]最后出现的位置
            }
        }
    </script>
</body>
</html>